package cn.itcast.web.servlet;

import cn.itcast.domain.ChangeList;
import cn.itcast.service.ChangeListService;
import cn.itcast.service.FileService;
import cn.itcast.service.impl.ChangeListServiceImpl;
import cn.itcast.service.impl.FileServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet("/updateChangeListCheckStateServlet")
public class UpdateChangeListCheckStateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1设置编码
        request.setCharacterEncoding("utf-8");
        //获取参数uid
        String uid = request.getParameter("uid");
        String uname = request.getParameter("uname");
        Map<String, String[]> map = request.getParameterMap();
        ChangeList changelist=new ChangeList();
        try {
            BeanUtils.populate(changelist,map);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        int id = changelist.getId();
        int yid = changelist.getYid();
        String info_a = changelist.getInfo_a();
        int check_state = changelist.getCheck_state();
        //调用service方法
        ChangeListService service=new ChangeListServiceImpl();
        service.updateChangeListCheckState(changelist);
        FileService service1=new FileServiceImpl();
        service1.tes(uid,id,yid,info_a,check_state,uname);
        request.getRequestDispatcher("/findChangeListByChangeStateServlet").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
